﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATMAaronKnoll
{
    class Withdrawals
    {
        int withdrawal;
        public void DisplayWithdrawalMenu(string WithdrawTranType)
        {
            //bool runApp = true;

            Console.WriteLine("\nHow much would you like to withdraw?");
            Console.WriteLine("\n\t1 - $20");
            Console.WriteLine("\t2 - $40");
            Console.WriteLine("\t3 - $60");            
            Console.WriteLine("\t4 - $100");
            Console.WriteLine("\t5 - $200");
            Console.WriteLine("\t6 - $10000");
            Console.WriteLine("\t7 - Cancel Transaction");
            Console.Write("\nPlease enter a numeric option: ");
            ConsoleKeyInfo keyPressed = Console.ReadKey();
            if (keyPressed.Key == ConsoleKey.Escape)
            {
                Console.Clear();
            }
            else
            switch (keyPressed.Key)
            {
                case ConsoleKey.NumPad1:
                case ConsoleKey.D1:
                    withdrawal = 20;
                    Console.WriteLine("\n\nThank you for the withdrawal, $20 will be deducted from your account balance.");
                    break;

                case ConsoleKey.NumPad2:
                case ConsoleKey.D2:
                    withdrawal = 40;
                    break;

                case ConsoleKey.NumPad3:
                case ConsoleKey.D3:
                    withdrawal = 60;
                    break;

                case ConsoleKey.NumPad4:
                case ConsoleKey.D4:
                    withdrawal = 100;
                    break;

                case ConsoleKey.NumPad5:
                case ConsoleKey.D5:
                    withdrawal = 200;
                    break;

                case ConsoleKey.NumPad6:
                case ConsoleKey.D6:
                    withdrawal = 10000;
                    break;

                case ConsoleKey.NumPad7:
                case ConsoleKey.D7:
                    Console.WriteLine("\n\nPress any key to return to the main menu.");
                    Console.ReadKey();
                    Console.Clear();
                    break;

            }
            if (ATM.CheckBills(withdrawal / 20))
            {
                if (Accounts.WithdrawCash(withdrawal))
                {
                    ATM.DispenseBills(withdrawal / 20);
                    Console.Clear();
                    Console.WriteLine("\nPlease Wait...");
                    System.Threading.Thread.Sleep(2000);
                    Console.Write("\nYour cash is ready below. Now returning to the main menu...");
                    System.Threading.Thread.Sleep(3500);
                    Console.Clear();
                }
                else
                {
                    Console.Write("\n\nIncufficient funds in account");
                    Console.WriteLine("\n\nReturning to the main menu");
                    System.Threading.Thread.Sleep(3000);
                    Console.Clear();
                }
            }
            else
            {
                Console.Clear();
                Console.Write("\nInsufficient funds in machine.");
                System.Threading.Thread.Sleep(3000);
            }
            
        }
    }
}
